{{/* 文章许可证信息组件

  显示文章的版权和许可证信息

  @context {page} . 当前文章页面对象
*/}}

{{/* 构建许可证配置 */}}
{{ $license := dict }}

{{/* 设置默认值 */}}
{{ $defaults := dict
  "show" true
  "author" (.Site.Params.author.name | default "")
  "name" "CC BY-NC-SA 4.0"
  "description" "本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。"
  "url" "https://creativecommons.org/licenses/by-nc-sa/4.0/"
  "displayName" "知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议"
}}


{{ $license = $defaults }}
{{ with .Site.Params.post.license }}
  {{ $license = merge $license . }}
{{ end }}
{{ with .Params.license }}
  {{ $license = merge $license . }}
{{ end }}


{{ if $license.show }}
  <div class="post-license bg-muted/30 border-border mb-8 rounded-xl border p-6">
    <div class="flex items-start gap-4">
      <!-- 许可证图标 -->
      <div
        class="bg-primary/10 flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-lg">
        {{ partial "features/icon.html" (dict "name" "license" "size" "lg" "ariaLabel" "许可证") }}
      </div>

      <!-- 许可证信息 -->
      <div class="flex-1 min-w-0">
        <h3 class="text-foreground mb-2 text-lg font-semibold">
          {{ i18n "license.title" | default "版权声明" }}
        </h3>

        <div class="text-muted-foreground space-y-2 text-sm">
          <!-- 作者信息 -->
          {{ with $license.author }}
          <p>
            <strong>{{ i18n "license.author" | default "作者" }}:</strong>
            {{ . }}
          </p>
          {{ end }}

          <!-- 文章链接 -->
          <p>
            <strong>{{ i18n "license.link" | default "链接" }}:</strong>
            <a
              href="{{ .Permalink }}"
              class="text-primary hover:text-primary/80 transition-colors break-all hyphens-auto duration-200">
              {{ .Permalink }}
            </a>
          </p>

          <!-- 许可证类型 -->
          <p>
            <strong>{{ i18n "license.type" | default "许可证" }}:</strong>
            {{ with $license.url }}
              <a
                href="{{ . }}"
                target="_blank"
                rel="noopener noreferrer"
                class="text-primary hover:text-primary/80 transition-colors duration-200">
                {{ $license.displayName }}
              </a>
            {{ else }}
              <span class="text-foreground">{{ $license.displayName }}</span>
            {{ end }}
          </p>

          <!-- 许可证说明 -->
          {{ with $license.description }}
          <p class="text-xs">
            {{ . }}
          </p>
          {{ end }}
        </div>
      </div>
    </div>
  </div>
{{ end }}